//
//  StripeApiClient.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/8/1.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "StripeApiClient.h"
#import <AFNetworking.h>
#import "EJSPreparePayForOrderRequest.h"
#import "JSONKit.h"

static StripeApiClient *k_StripeApiClient = nil;

@implementation StripeApiClient

+ (instancetype)sharedInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        k_StripeApiClient = [[self alloc] init];
    });
    return k_StripeApiClient;
}

- (void)createCustomerKeyWithAPIVersion:(nonnull NSString *)apiVersion completion:(nonnull STPJSONResponseCompletionBlock)completion {
    [[HUDHelper sharedInstance] loading];
    EJSPreparePayForOrderRequest *req = [EJSPreparePayForOrderRequest new];
    req.orderId = self.orderId;
    req.apiVersion = apiVersion;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] syncStopLoading];
        self.preparePayForModel = response.data;
        completion([self.preparePayForModel.stripe_key getJsonDictionary],nil);
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] syncStopLoading];
        [[HUDHelper sharedInstance] tipMessage: response.message];
    }];
    
    
//    NSString *url = [NSString stringWithFormat:@"%@/api/order/readyToPay",ServerAddressWeb];
//    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
//    sessionManager.requestSerializer.timeoutInterval = 20;
//    [sessionManager POST:url parameters:@{@"api_version": apiVersion} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
//        completion(responseObject,nil);
//    }failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error){
//        completion(nil,error);
//    }];
}

@end
